#include <stdio.h>
#include <stdlib.h>

void int_to_float()
{
    int a = 1;
    int * pint = NULL;
    float * pfloat = NULL;
    float f = 0.0;

    pint = &a;
    printf("%d\n", *pint);   // 1

    /* warning: assignment from incompatible pointer type [enabled by default] */
    pfloat = pint;           // 把pint指向地址值赋给浮点指针，为零
    printf("%f\n", *pfloat); // 0.000000

    /* (line):5  error: pointer value used where a floating point value was expected */
    /* (line):12 error: incompatible types when assigning to type 'float *' from type 'float' */
    //pfloat = (float)pint; // 把pint指向地址值强制转换成浮点数，并赋给一个浮点指针，类型不匹配    

    /* (line):5 error: pointer value used where a floating point value was expected */
    /* (line):12 error: incompatible types when assigning to type 'float *' from type 'float' */
    //pfloat = (float)&pint; // 把pint地址值强制转换成浮点数，并赋给一个浮点指针，类型不匹配

    /* :12: error: incompatible types when assigning to type 'float *' from type 'float' */
    //pfloat = (float)*pint;  // 把一个整数值强制转换成浮点数，并赋给一个浮点指针，类型不匹配

    pfloat = (float *)pint;   // 把pint指向地址值强制转换成浮点指针，为零
    printf("%f\n", *pfloat);  // 0.000000

    pfloat = (float *)&pint;  // 把pint地址值强制转换成浮点指针，随机值
    printf("%f\n", *pfloat);  // -15304149222902214656.0000000

    /* :14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] */
    /* 从不同大小的整数强制转换为指针 */
    pfloat = (float *)*pint;  // 把一个整数值强制转换成浮点指针，段出错
    // printf("%f\n", *pfloat);  // segmentation fault (core dumped)

    /* :14: error: lvalue required as unary '&' operand */
    // pfloat = &((float)*pint);

    f = (float)*pint;
    pfloat = &f;
    printf("%f\n", *pfloat);   // 1.000000

    /* error: lvalue required as unary '&' operand */
    //pfloat = &(float)a;

}

void array_to_float()
{
    int array[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    int * pint = NULL;
    float * pfloat = NULL;
    
    
}

void main()
{
    int_to_float();

    array_to_float();
}





